Skip to content

Conversation

@vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented May 28, 2025

Extracted from #140529

Issue #139128 needs to find the last one in the file.

It's almost NFC, as the order of existing user of inSectionBlame is unimportant.

Created using spr 1.3.6
@llvmbot
Copy link
Member

llvmbot commented May 28, 2025

@llvm/pr-subscribers-llvm-support

Author: Vitaly Buka (vitalybuka)

Changes

Issue #139128 needs to find the last one in the file.


Full diff: https://github.com/llvm/llvm-project/pull/141697.diff

2 Files Affected:

  • (modified) llvm/lib/Support/SpecialCaseList.cpp (+4-3)
  • (modified) llvm/unittests/Support/SpecialCaseListTest.cpp (+3-5)
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 47ff3e24706a4..f9b5aafe88e98 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -14,6 +14,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/SpecialCaseList.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/LineIterator.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -66,10 +67,10 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
 }
 
 unsigned SpecialCaseList::Matcher::match(StringRef Query) const {
-  for (const auto &Glob : Globs)
+  for (const auto &Glob : reverse(Globs))
     if (Glob->Pattern.match(Query))
       return Glob->LineNo;
-  for (const auto &[Regex, LineNumber] : RegExes)
+  for (const auto &[Regex, LineNumber] : reverse(RegExes))
     if (Regex->match(Query))
       return LineNumber;
   return 0;
@@ -213,7 +214,7 @@ bool SpecialCaseList::inSection(StringRef Section, StringRef Prefix,
 unsigned SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix,
                                          StringRef Query,
                                          StringRef Category) const {
-  for (const auto &S : Sections) {
+  for (const auto &S : reverse(Sections)) {
     if (S.SectionMatcher->match(Section)) {
       unsigned Blame = inSectionBlame(S.Entries, Prefix, Query, Category);
       if (Blame)
diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp
index eea185d142891..05e4e83090fd9 100644
--- a/llvm/unittests/Support/SpecialCaseListTest.cpp
+++ b/llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -311,8 +311,7 @@ TEST_F(SpecialCaseListTest, LinesInSection) {
   std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("fun:foo\n"
                                                              "fun:bar\n"
                                                              "fun:foo\n");
-  // FIXME: Get the last one for #139128.
-  EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo"));
+  EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo"));
   EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar"));
 }
 
@@ -322,8 +321,7 @@ TEST_F(SpecialCaseListTest, LinesCrossSection) {
                                                              "fun:foo\n"
                                                              "[sect1]\n"
                                                              "fun:bar\n");
-  // FIXME: Get the last one for #139128.
-  EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo"));
-  EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar"));
+  EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo"));
+  EXPECT_EQ(5u, SCL->inSectionBlame("sect1", "fun", "bar"));
 }
 }

@vitalybuka
Copy link
Collaborator Author

@qinkunbao Please approve and merge if everything is OK here.

qinkunbao added 2 commits May 27, 2025 18:19
Created using spr 1.3.6
Created using spr 1.3.6
@vitalybuka vitalybuka added the skip-precommit-approval PR for CI feedback, not intended for review label May 28, 2025
Created using spr 1.3.6
vitalybuka pushed a commit that referenced this pull request May 28, 2025
Issue #139128 needs to find the last one in the file.

Pull Request: #141697
@vitalybuka vitalybuka closed this May 28, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 28, 2025
… order

Issue #139128 needs to find the last one in the file.

Pull Request: llvm/llvm-project#141697
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:support skip-precommit-approval PR for CI feedback, not intended for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants